package com.jianglin.state2.controller;

import com.jianglin.state2.core.ResponsePack;
import com.jianglin.state2.dao.entity.Wage;
import com.jianglin.state2.model.params.WageAddParams;
import com.jianglin.state2.model.params.WageUpdateParams;
import com.jianglin.state2.service.WageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@ResponsePack
@RequestMapping("/wage")
@Api(tags = {"工资信息"})
public class WageController {

    private final WageService wageService;

    @Autowired
    public WageController(WageService wageService) {
        this.wageService = wageService;
    }

    @GetMapping("/all")
    @ApiOperation("获得所有工资信息")
    public List<Wage> getAll() {
        return wageService.list();
    }

    @PostMapping("/add")
    @ApiOperation("添加工资")
    public boolean saveDesk(@Validated @RequestBody WageAddParams wageAddParams) {
        Wage wage = wageAddParams.convertOut();
        return wageService.save(wage);
    }

    @PutMapping("/{id}")
    @ApiOperation("更新工资信息")
    public boolean updateEmployee(@ApiParam("工资编号") @PathVariable Integer id,
                                  @Validated @RequestBody WageUpdateParams wageUpdateParams){
        Wage wage = wageUpdateParams.convertOut();
        wage.setWageId(id);
        return wageService.updateById(wage);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除某类工资")
    public boolean deleteWage(@ApiParam("工资编号") @PathVariable Integer id) {
        return wageService.removeById(id);
    }
}